package cn.com.huzo.repository.hr.impl;

import cn.com.huzo.model.entities.hr.LeaveApplicationEntity;
import cn.com.huzo.repository.hr.LeaveApplicationRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 请假单数据访问对象
 *
 * @author 吴旭
 */
@Repository("LeaveApplicationRepository")
public class LeaveApplicationRepositoryImpl extends GenericRepositoryImpl<LeaveApplicationEntity, String>
        implements LeaveApplicationRepository {

    private final String namespace = "cn.com.huzo.repository.hr.LeaveApplicationRepository";

    /**
     * 构造函数,设置the instance to LeaveApplicationRepositoryImpl.class.
     */
    public LeaveApplicationRepositoryImpl() {
        super(LeaveApplicationEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LeaveApplicationEntity fetchByKey(String key) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<LeaveApplicationEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String insert(LeaveApplicationEntity instance) {
        getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getLeaveApplicationId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(LeaveApplicationEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer setProcessInstanceId(String leaveApplicationId, String processInstanceId) {
        Map<String, Object> paramtersMap = new HashMap();
        paramtersMap.put("LeaveApplicationId", leaveApplicationId);
        paramtersMap.put("ProcessInstanceId", processInstanceId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "setProcessInstanceId"), paramtersMap);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer setStatus(String leaveApplicationId, Short status) {
        Map<String, Object> paramtersMap = new HashMap();
        paramtersMap.put("LeaveApplicationId", leaveApplicationId);
        paramtersMap.put("Status", status);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "setProcessInstanceId"), paramtersMap);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
